/**
 * create by ck on 2017/6/27.
 */
$(document).ready(function(){
    var $dataGrid   = new xhDataGrid($('#List'), 'Appserver/getWhiteList'),
        $btSave     = $('#bt_form_add'),
        $form       = new xhForm($('#xh_form'));
    $form.parse().bindRequired($btSave);
    $dataGrid.parseToolbar().init().activeButton([], ['bt_list_del', 'bt_list_enable', 'bt_list_disable']);
    xhExtra.bindDefaultFun($dataGrid, $form, $btSave, {
        modifyUrl: 'Appserver/createWhiteList',
        deleteUrl: 'Appserver/delWhiteList',
        idField: 'id'
    });
    //列表加载后合并单元格
    $dataGrid.onLoadSuccess = function(data){
        $dataGrid.clear();
        if (data.rows.length <= 0) return false;
        $dataGrid.mergeCells(['deviceType']);
    };
    //启用按钮
    $('#bt_list_enable').click(function(){
        if(xhExtra.buttonDisabled($(this))) return false;
        setStatus(1);
    });
    //禁用按钮
    $('#bt_list_disable').click(function(){
        if(xhExtra.buttonDisabled($(this))) return false;
        setStatus(2);
    });
    //处理启用/禁用
    function setStatus(_status) {
        var ids = $dataGrid.getSelectValues('id');
        if(!ids) return true;
        xhExtra.ajaxRequest('Appserver/modifyWhiteListStatus', {ids: ids, status: _status}, {table: $dataGrid});
    }
});